/**
 * 
 * @author Peter & Daniel
 *
 */
public class MimeType {
	/**
	 * 
	 * @param path (String, Pfad zur Datei)
	 * @return String, MimeType
	 */
	static synchronized public String getMimeType(String path){
		int s = path.lastIndexOf('.');
		if(s != -1){
		return (String) extToMime.get(path.substring(s));	
		}
		return "content/unknown";
	}
	
    static java.util.Hashtable<String, String> extToMime = new java.util.Hashtable<String, String>();

    static {
        fillMap();
    }
    
    /**
     * 
     * @param k Dateiendung
     * @param v MimeType
     */
    static void setSuffix(String k, String v) {
    	extToMime.put(k, v);
    }

    static void fillMap() {
        setSuffix("", "content/unknown");
        setSuffix(".uu", "application/octet-stream");
        setSuffix(".exe", "application/octet-stream");
        setSuffix(".ps", "application/postscript");
        setSuffix(".zip", "application/zip");
        setSuffix(".sh", "application/x-shar");
        setSuffix(".tar", "application/x-tar");
        setSuffix(".snd", "audio/basic");
        setSuffix(".au", "audio/basic");
        setSuffix(".wav", "audio/x-wav");
        setSuffix(".gif", "image/gif");
        setSuffix(".jpg", "image/jpeg");
        setSuffix(".jpeg", "image/jpeg");
        setSuffix(".htm", "text/html");
        setSuffix(".html", "text/html");
        setSuffix(".text", "text/plain");
        setSuffix(".c", "text/plain");
        setSuffix(".cc", "text/plain");
        setSuffix(".c++", "text/plain");
        setSuffix(".h", "text/plain");
        setSuffix(".pl", "text/plain");
        setSuffix(".txt", "text/plain");
        setSuffix(".java", "text/plain");
    }
}
